package com.yang.frost.blueberry.service.impl;

import com.yang.frost.blueberry.mapper.CmsCategoryMapper;
import com.yang.frost.blueberry.service.CmsCategoryService;
import com.yang.frost.blueberry.util.ApiResult;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 10296
 * @date 2021/3/11
 * @Description:
 */
@Service
public class CmsCategoryServiceImpl implements CmsCategoryService {
    private Logger logger = LoggerFactory.getLogger(CmsCategoryService.class);

    @Autowired
    private CmsCategoryMapper cmsCategoryMapper;

    @Override
    public ApiResult insertCategory(Map<String, Object> paramsMap) {
        Map<String, Object> retMap = new HashMap<>();

        int i = cmsCategoryMapper.insertCategory(paramsMap);

        logger.info(">>>>>>>>>>>>" + i);
        return ApiResult.ok(i);

    }

    @Override
    public ApiResult qryCategoryList(Map<String, Object> paramsMap) {
        Map<String, Object> resultMap = new HashMap<>();
        int pageIndex = MapUtils.getIntValue(paramsMap, "pageIndex");
        int pageSize = MapUtils.getIntValue(paramsMap, "pageSize");
        List<Map<String, Object>> retList = cmsCategoryMapper.qryCategoryList(paramsMap);
        int i = cmsCategoryMapper.qryCategoryCounts(paramsMap);
        resultMap.put("rows", retList);
        resultMap.put("pageIndex", pageIndex);
        resultMap.put("pageSize", pageSize);
        resultMap.put("total", i);

        return ApiResult.ok(resultMap);
    }

    @Override
    public ApiResult qryCategoryNodeTree(Map<String, Object> paramsMap) {
        List<Map<String, Object>> retList = cmsCategoryMapper.qryCategoryList(paramsMap);
        return null;
    }

    @Override
    public ApiResult deleteCategory(String categoryId) {
        int i = cmsCategoryMapper.deleteCategory(categoryId);
        return ApiResult.ok(i);
    }

    @Override
    public ApiResult updateCategory(Map<String, Object> paramsMap) {
        int i = cmsCategoryMapper.updateCategory(paramsMap);
        return ApiResult.ok(i);
    }
}
